package pais.db;

import java.io.IOException;

import papos.rowset.AdvRandomAccessFile;
import papos.rowset.KeyDesc;
import papos.rowset.Storable;


public class Keyword implements Storable {
  public static final int MAX_KEYWORD_LEN = 24;

  /* fields should be public in order to be stored in StorageSystem */  
  public long   KID_;    // primary key for keyword table
  public String keyword_;
  public long   UID_;
  public int    offset_;

  public Keyword() {
  }
  public Keyword(long KID, String keyword, long UID, int offset ) {
    KID_ = KID;
    keyword_ = keyword;
    UID_ = UID;
    offset_ = offset;
  }
  public KeyDesc[] getKeyDesc() {
    return new KeyDesc[] { 
        new KeyDesc("KID_", false), // primary key
        new KeyDesc("keyword_", true),
        new KeyDesc("UID_", true)
    };
  }
  public int maxSize() {
    return 8 + (4+MAX_KEYWORD_LEN) + 8 + 4;
  }
  public Object clone() {
    return new Keyword( KID_, keyword_, UID_, offset_ );
  }
  public void writeObject(AdvRandomAccessFile raf) throws IOException {
    raf.writeLong(KID_);
    raf.writeString(keyword_,MAX_KEYWORD_LEN);
    raf.writeLong(UID_);
    raf.writeLong(offset_);
  }
  public void readObject(AdvRandomAccessFile raf) throws IOException, ClassNotFoundException {
    KID_     = raf.readLong();
    keyword_ = raf.readString(MAX_KEYWORD_LEN);
    UID_     = raf.readLong();
    offset_  = raf.readInt();
  }

  public String getKeyword() {
    return keyword_;
  }
  public void setKeyword(String keyword) {
    this.keyword_ = keyword;
  }
  public long getUID() {
    return UID_;
  }
  public void setUID(long uid) {
    UID_ = uid;
  }
  public int getOffset() {
    return offset_;
  }
  public void setOffset(int offset) {
    this.offset_ = offset;
  }
  public long getKID() {
    return KID_;
  }
  public void setKID(long kid) {
    KID_ = kid;
  }
  public String toString() {
    return "Keyword(KID="+getKID()+",Keyword="+getKeyword()+",UID="+getUID()+",Offset="+getOffset();		
  }
}
